//
//  YYTopicHeaderView.swift
//  STMusic
//
//  Created by stoneobs on 17/5/10.
//  Copyright © 2017年 stoneobs. All rights reserved.
// //**********************话题顶部***************************

import UIKit

class YYTopicHeaderView: UICollectionReusableView {
    
    var  headerViewHeight:CGFloat = 300.0;
    var model:YYTopicModel? = YYTopicModel(){
    
        didSet{
        
            self.userView?.userModel = model?.user;
            let date:NSDate = NSDate.init(timeIntervalSince1970: TimeInterval((self.model?.start_time)!)!)
            self.userView?.timeLabel?.text = date.yyyyMMddByLineWithDate()  + "  开始";
            if let title = model?.title{
                self.taglable?.text = "#" + title + "#";
            }
            if let desSrting = model?.desc {
                
                let  des:NSString = NSString.init(string: desSrting)
                let height = des.heigthWithwidth((self.deslabel?.width)!, font: 13);
                
                self.deslabel?.numberOfLines = 0;
                self.deslabel?.height = height;
                self.deslabel?.text = desSrting;
                
            }

            

            
            self.whiteView?.height = (self.deslabel?.bottom)! + 20 ;
            
            self.topView?.height = (self.whiteView?.bottom)! + 35;
            
            self.header?.top = (self.topView?.bottom)!;
            
            self.headerViewHeight = (self.header?.bottom)!;
        
        }
    
    }
    
    var topView:UIView? //头部view
    var whiteView:UIView?
    var userView:YYFrequentlyUserCellHeader?
    var taglable:STLabel?
    var deslabel:STLabel?
    
    
    var header:UIView? //悬停View
    
    var segmentButton:STSegementButton?
    
    var playButton:STButton?//播放
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        initSubview()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    func initSubview() {
        //topView
        self.topView = UIView.init(frame: .init(x: 0, y: 0, width: SCREEN_WIDTH, height: 250));
        self.topView?.backgroundColor = YYThemeStyleManger.defultManger.gradualColor(frame: (self.topView?.bounds)!);
        self.addSubview(self.topView!);
        
        self.whiteView = UIView.init(frame: .init(x: 10, y: 0, width: SCREEN_WIDTH - 20, height: 200));
        self.whiteView?.backgroundColor = .white;
        self.whiteView?.layer.cornerRadius = 3;
        self.whiteView?.clipsToBounds = true;
        self.topView?.addSubview(self.whiteView!);
        
        self.userView = YYFrequentlyUserCellHeader.init(frame: .init(x: 10, y: 20, width: (self.whiteView?.width)! - 20, height: 50));
        self.whiteView?.addSubview(self.userView!);
        
        self.taglable = STLabel.init(frame: .init(x: 10 + 15 , y: (self.userView?.bottom)! + 10, width: (self.whiteView?.width)! - 50, height: 15), text: "#记录孩子的音乐碎片#", textColor:.black , font: 15, isSizetoFit: false, textAlignment: .left);
        self.whiteView?.addSubview(self.taglable!);
        
        self.deslabel = STLabel.init(frame: .init(x: 10 + 15 , y: (self.taglable?.bottom)! + 10, width: (self.whiteView?.width)! - 50, height: 80), text: "", textColor:SecendTextColor , font: 13, isSizetoFit: false, textAlignment: .left);
        self.whiteView?.addSubview(self.deslabel!);
        
        self.topView?.addSubview(self.whiteView!);
        
        //悬停view,滑动到一定位置显示  vc.view 上的
        weak var weakSelf = self;
        self.header = UIView.init(frame: .init(x: 0, y: 0, width: SCREEN_WIDTH, height: 50));
        self.header?.backgroundColor = YYThemeStyleManger.defultManger.gradualColor(frame: (self.header?.bounds)!);
        self.header?.top = (self.topView?.bottom)!;
        self.addSubview(self.header!);
        
        self.segmentButton  = STSegementButton.init(frame: .init(x: 20, y: 0, width: 160, height: 40), andTitle: ["最热","最新"], handle: { (but) in
            
        });
        self.segmentButton?.butTitleColor = ThirdTextColor;
        self.segmentButton?.lineColor = .clear;
        self.segmentButton?.backgroundColor = .clear;
        self.segmentButton?.butTitleSelectedColor = .white;
        self.segmentButton?.lineSelectedColor = .white;
        self.segmentButton?.autoMoveWithClic = true;
        self.segmentButton?.isShowSpringAnimation = false;
        self.segmentButton?.centerY = (self.header?.height)! / 2;
        self.header?.addSubview(self.segmentButton!);
        
        self.playButton = STButton.init(frame: .init(x: SCREEN_WIDTH - 100 , y: 0, width: 90, height: 40), title: "一键播放", titleColor: .white, titleFont: 15, cornerRadius: 0, backgroundColor: .clear, backgroundImage: nil, image: nil);
        self.playButton?.centerY = (self.header?.height)! / 2;
        self.playButton?.contentHorizontalAlignment = .right;
        self.header?.addSubview(self.playButton!);

        self.addSubview(self.header!);
    }
}
